﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FOModels.Customer;
using System.Data;
using DataAccess.Customer;
namespace Bussiness.Customer
{
    public class CustomerBLL
    {
        private CustomerDAL dal;
        public CustomerBLL()
        {
            dal = new CustomerDAL();
        }
        public int InsertCustomer(CustomerModels cus)
        {
            if (dal.InsertCustomer(cus) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int UpdateCustomerInfo(CustomerModels cus)
        {
            if (dal.UpdateCustomerInfo(cus) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public CustomerModels Top1Customer()
        {
            CustomerModels cus = new CustomerModels();
            DataTable tb = dal.Top1Customer();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    cus.CustomerID = int.Parse(row[0].ToString());
                    cus.CustomerName = row[1].ToString();
                    cus.Email = row[2].ToString();
                    cus.Phone = row[3].ToString();
                    cus.Address = row[4].ToString();
                    cus.DOB = row[5].ToString();
                    cus.InComing = row[5].ToString();
                }
            }
            return cus;
        }
        public CustomerModels SearchCustomerbyEmail(string email)
        {
            CustomerModels cus = new CustomerModels();
            DataTable tb = dal.SearchCustomerbyEmail(email);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    cus.CustomerID = int.Parse(row[0].ToString());
                    cus.CustomerName = row[1].ToString();
                    cus.Email = row[2].ToString();
                    cus.Phone = row[3].ToString();
                    cus.Address = row[4].ToString();
                    cus.DOB = row[5].ToString();
                    cus.InComing = row[5].ToString();
                }
                return cus;
            }
            else
            {
                return null;
            }

        }
    }
}
